Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Grow the Uint16Array if the page size overflows 1MB #798

Merged
merged 4 commits into from
Apr 16, 2018

Conversation

chadhietala
Copy link
Member

@chadhietala chadhietala commented Apr 12, 2018

Fixes #797

private sizeCheck() {
this.pageSize++;
if (this.pageSize >= PAGE_SIZE) {
debugger;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔪

@@ -71,14 +74,26 @@ export class Heap implements CompileTimeHeap {
this.table = table;
this.offset = this.heap.length;
this.handle = handle;
this.pageSize = this.heap.length;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this.pageSize keeps track of the used space in the last page of the heap, I think this will only work if serializedHeap.buffer is a multiple of PAGE_SIZE.
If in stead, we keep track of the free space, then this should work.

this.table = [];
}
}

push(item: number): void {
this.heap[this.offset++] = item;
this.sizeCheck();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size should be checked before an element is put on the heap, otherwise a size check should also be executed in the constructor in case of a serializedHeap.
This has also the advantage that we don't need to grow the heap in case we end on a page boundary 😃

private sizeCheck() {
this.pageSize++;
if (this.pageSize >= PAGE_SIZE) {
let heap = slice(this.heap, 0, this.offset);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why the copy of the heap is necessary, is it not enough to keep a reference to the old heap in a local variable?

@@ -181,6 +196,7 @@ export class Heap implements CompileTimeHeap {

pushPlaceholder(valueFunc: () => number): void {
let address = this.offset++;
this.sizeCheck();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, the size should be checked before an element is put on the heap.

@rondale-sc
Copy link
Contributor

Is this fix going to land in a point release of Ember 3.1 as a hotfix?

@rwjblue rwjblue merged commit a28b777 into master Apr 16, 2018
@rwjblue rwjblue deleted the fix-array-growth branch April 16, 2018 18:55
@rwjblue
Copy link
Member

rwjblue commented Apr 16, 2018

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants